/*
 *  Copyright (C) 1993  Robert Davis
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of Version 2, or any later version, of 
 *  the GNU General Public License as published by the Free Software 
 *  Foundation.
 */


static char RCSId[]="$Id: DataFileThreeDPane.m,v 1.3 1993/05/30 09:10:10 davis Exp $";

#import <appkit/Application.h>
#import <appkit/FormCell.h>
#import <appkit/Matrix.h>
#import <appkit/Panel.h>
#import <appkit/TextFieldCell.h>
#import <appkit/View.h>

#import <objc/NXStringTable.h>

#import "DataFileThreeDPane.h"
#import "DataOptionsPanel.h"
#import "FunctionObject.h"
#import "Status.h"

@implementation DataFileThreeDPane

- init
{
    [super init];

    [NXApp loadNibSection: "DataFileThreeDPane.nib"
		    owner: self
		withNames: NO
		 fromZone: [self zone]];

    return self;
}



- setDetailed:sender
{
    struct coldat	*cd = [[doc function] columnData];
    BOOL		isDetailed = [sender state];

    if (isDetailed != cd->isOn) {
	BOOL	report = [status report];

	cd->isOn = isDetailed;

	[status setReport:NO];
	[self setZOnly:zOnlyRadioMatrix];
	[status setReport:report];
	[status reportSettingsChange:self];

    }

    return self;
}



- setColumnsData:sender
{
    FunctionObject	*f = [doc function];
    struct coldat	*columnData = [f columnData];
    int			value = [[sender selectedCell] intValue];

    if ((value <= columnData->number) && (value > 0)){

	switch ([sender selectedTag]) {

	case THREED_XCOL:	columnData->x = value; break;
	case THREED_YCOL:	columnData->y = value; break;
	case THREED_ZCOL:
	case THREED_ZCOLONLY:	columnData->z = value; break;

	}

	[status reportSettingsChange:self];

    }

    if ([self forceUpdateStatus:status doc:doc])
	[[infoField superview] display];	/* Display box */

    return self;
}


- setZOnly:sender;
{
    BOOL		useZOnly = ([sender selectedTag] == Z_ONLY);
    FunctionObject	*f = [doc function];
    struct coldat	*columnData = [f columnData];

    if (!useZOnly != columnData->useX) {
	columnData->useX = !useZOnly;
	columnData->useY = !useZOnly;
	columnData->useZ = YES;

	/*  
	 *  Parametric mode should be on if using Z Only mode.  Off 
	 *  otherwise. 
	 */
	if ([status parametric] == useZOnly)
	    [status setParametric:!useZOnly];
	else
	    [status reportSettingsChange:self];
    }

    if ([self forceUpdateStatus:status doc:doc])
	[[infoField superview] display];	/* Display box */

    return self;
}


- (BOOL)updateStatus:aStatus doc:aDoc
{
    FunctionObject	*f;

    [super updateStatus:aStatus doc:aDoc];

    f = [doc function];

    if (f) {

	struct coldat	*c = [f columnData];
	char		info[1023];
	BOOL		enabled = c->isOn;
	Window		*viewWindow;

	[(viewWindow = [view window]) disableDisplay];

	[detailedButton setState:enabled];

	if (c->number == 1)
	    strcpy (info, [stringSet valueForStringKey:"columnsInfoSingular"]);
	else
	    sprintf (info, [stringSet valueForStringKey:"columnsInfoPlural"],
		     c->number);

	[infoField setStringValue: info];
	[infoField setEnabled: enabled];
	[infoLine2 setEnabled: enabled];

	[zOnlyRadioMatrix setEnabled:enabled];
	[zOnlyRadioMatrix selectCellWithTag:c->useX ? !Z_ONLY : Z_ONLY];

	[xColField setEnabled:(enabled && c->useX)];
	[xColField setIntValue:c->x];

	[yColField setEnabled:(enabled && c->useY)];
	[yColField setIntValue:c->y];

	[zColField setEnabled:(enabled && c->useZ && c->useX)];
	[zColField setIntValue:c->z];

	[zOnlyColField setEnabled:(enabled && c->useZ && !c->useX)];
	[zOnlyColField setIntValue:c->z];

	[viewWindow reenableDisplay];

    }

    return YES;
}


// Shuts up the compiler about unused RCSId
- (const char *) rcsid
{
    return RCSId;
}

@end
